#ifndef AICLIENT_H
#define AICLIENT_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QString>
#include <QSettings>

class AIClient : public QObject
{
    Q_OBJECT

public:
    explicit AIClient(QObject *parent = nullptr);

    void sendQuestion(const QString &question, const QString &conversationId);
    void setApiKey(const QString &apiKey);
    QString getApiKey() const;

signals:
    void answerReady(const QString &answer);
    void errorOccurred(const QString &error);

private slots:
    void onReplyFinished(QNetworkReply *reply);

private:
    QNetworkAccessManager *m_networkManager;
    QSettings *m_settings;
    QMap<QString, QStringList> m_conversationContexts; // 存储对话上下文

    QString getApiUrl() const;
    QByteArray buildRequestData(const QString &question, const QString &conversationId);
    void updateConversationContext(const QString &conversationId,
                                  const QString &question, const QString &answer);
};

#endif // AICLIENT_H
